angular.module('Controller')

.controller('QgyMemberDetailCtrl', ($scope,NgTableParams,menuManage,wfAlert,$localStorage,commonUtil,commonConstant,$rootScope,$uibModal,$http) ->
    console.log($rootScope.pageType)
    if $rootScope.pageType=='member-detail'
#接受数据:{houseId,contractId,house,contract}
        data=angular.copy($rootScope.pageParams)
        $scope.memberId=data.memberId
        $scope.member=data.member
        $rootScope.pageParams=undefined
        $rootScope.pageType=undefined
    loadData=()->
        $http.get("/customerUser/#{$scope.memberId}")
        .success((resp)->
            if resp.code==0
                $scope.member=resp.message
        )
    loadData()
    $scope.sexList=commonConstant.qgySexList()
    _.extend $scope,
        openCotenant:(type,item)->
            modal=showCotenantModal(type,item)
            modal.result.then((modalData)->
                if modalData && type!='view'
                    item=modalData
            )
            ''
        payLease:()->
            $http.get('/bill',params:{page:0,size:999,type:1,contractId:$scope.contract.id,status:1})
            .success((resp)->
                if resp.code==0
                    if resp.message.content.length>0 and resp.message.content[0].status==1
                        $scope.recentLeaseBill=resp.message.content[0]
                        showBillModal('',angular.copy($scope.recentLeaseBill))
                    else
                        wfAlert.toastInfo('无未支付的房租账单')
                        return
                else
                    wfAlert.toastError(resp.message)
            )
        printContract:()->
            cnt=$scope.contract
            if cnt and cnt.contractPdf
                window.open(cnt.contractPdf, '_blank')
            else
                wfAlert.toastError('合同pdf文件未生成')
            ''
        selectTab:  (event, tabID)->
            console.log($('#memberTab .active'))
            $('#memberTab .active').removeClass('active')
            $('#memberTab #' + tabID).addClass('active')
            $('#memberTabContent .active').removeClass('active')
            $('#memberTabContent #' + tabID + 'Pane').addClass('active')
            return
    showCotenantModal=(type,data)->
        modal = $uibModal.open({
            animation: true,
            size:'lg',
            appendTo: $("#modalContent:eq(0)"),
            controller: 'QgyCotenantModalCtrl',
            templateUrl: 'templates/business-manage/cotenant-modal/cotenant-modal.html',
            resolve: {
                items:  ()->{type:type,data:data}
            }
        })
    showBillModal=(type,data)->
        $scope.modal = $uibModal.open({
            animation: true,
            appendTo: $("#modalContent:eq(0)"),
            controller: 'QgyRentPayModalCtrl',
            templateUrl: 'templates/business-manage/rent-pay-modal/rent-pay-modal.html',
            resolve: {
                items:  ()->{type: type, data: data}
            }
        })
        $scope.modal.result.then((modalData)->
            ''
        )
)